// 1. 请求数据 存起来 localStorage
// 2. 输入框
// 3. 搜索按钮点击从localStorage中取出数据
// 4. 搜索列表是树状组件 带复选框
// 5. 可以选中删除
// 6. 可以折叠
// 7. 搜索关键字高亮

import { getSearchData } from "./api/search";
import { SearchResposeType } from "./types/search";
let result: SearchResposeType[] = [];
let value: string = "";
async function load() {
  const res = await getSearchData();
  result = res;
  // result.map((item) => {
  //   item.children &&
  //     item.children.map((child) => {
  //       child.children?.map((item) => {
  //         item.children?.map((item) =>
  //           item.children?.map((item) => item.children?.map())
  //         );
  //       });
  //     });
  // });
}
load();

document.getElementById("search-btn")!.addEventListener("click", () => {
  searchData();
});

function changeInput(e: any) {
  console.log(value);
  value = e.target.value;
}
const inputDom = document.getElementById("search-input");
inputDom!.addEventListener("input", (e: any) => {
  console.log(value);
  value = e.target.value;
});

function searchData() {
  if (value && result) {
    // 深度优先搜索
    const searchResult = result.filter((item: SearchResposeType) => {
      if (item.label.includes(value)) {
        return item;
      }
    });
    console.log(searchResult);
  } else {
    console.log("稍等");
  }
}
